<?php $this->load->view(TEMPLATE_NAME.'/front/header'); ?>
<?php $this->load->view(TEMPLATE_NAME.'/front/side_left'); ?>
<script type="text/javascript">
function submitfrm()
{
	document.getElementById('dropdownform').submit();
}

function submitFilter(){
        var pageNumb = "<?php echo $page_num; ?>";
        var url = "<?php echo base_url();?>news/filter/<?php echo $dropdown_id;?>";
        if($("#news_categories").val()!=""){
            url = url + "/" +$("#news_categories").val();
        }
        else{
            url = url + "/all";
        }
        if($("#article_number_src").val()!=""){
            url = url + "/" + parseInt($("#article_number_src").val());
        }
        else{
            url = url + "/0";
        }
        if(pageNumb>0){
            url = url + "/" + "<?php echo $page_num; ?>";
        }
        window.location=url;
    }

function perpagefunction(perpagevalue)
{
	document.getElementById('perpage').value = perpagevalue;
	document.getElementById('dropdownform').submit();
	
}
</script>

<div class="page">
<h2>South Africa - News <a href="<?php echo site_url('news/news_startup')?>">Post News</a></h2>
<div style="margin-top: 10px;">
    <div class="categories_div">
        <label>Category: </label>
        <?php
            $js = 'id = "news_categories"'; 
            if(empty($categoryarray)){
                $categoryarray = array("" => "All");
            }
             echo form_dropdown('selection_criteria',$category_list,$category_selected,$js);
        ?>
    </div>
    <div class="article_number_div">
        <label>Article Number: </label>
        <input type="text" name="article_number_src" id="article_number_src" value="<?php echo $article_number;?>"/>
        <input type='submit' id="filter_go" class="article_number_src" value="GO" onclick="submitFilter()"/>
    </div>
</div>
<hr style="margin-bottom: 0px;"/>
<div class="localnews localnews2"> 
<!--<div class="clear"></div>-->
<!--<div>-->
<?php	

$attributes = array("id"=> 'dropdownform');
echo form_open('news/news',$attributes);
?>
<!--<div style="float:left; width:150px">-->	<!--selection criterias -->
Order
<?php
$js = 'onChange="submitfrm()"'; 
/*$selectionarray = array('1' => 'Newest to oldest',
						'2' => 'Most commented',
						'3' => 'Most Read',
						'4' => 'Most Liked',
						'5' => 'Oldest to Newest');*/
$selectionarray = array('1' => 'Newest to oldest',
						'2' => 'Most commented',
						'3' => 'Most Read',
						'4' => 'Most Liked',
						'5' => 'Oldest to Newest');
 echo form_dropdown('selection_criteria',$selectionarray,$dropdown_id,$js);
 
 
 ?>
<!--</div>-->		
<!--<div style="float:left">-->
<input type="hidden" name="perpage" id="perpage" />
<span> Display <a href="javascript:;" onclick="perpagefunction('15')" <?php if($perpage == '15') { ?>class="on" <?php } ?>>15</a> <a href="javascript:;" onclick="perpagefunction('20')" <?php if($perpage == '20') { ?>class="on" <?php } ?>>20</a> <a  href="javascript:;" onclick="perpagefunction('35')" <?php if($perpage == '35') { ?>class="on" <?php } ?>>35</a> items per page</span>
<?php echo form_close(); ?>
</div>
<!--<div class="clear"></div>
<div id="message"> -->
<ol class="realtime">
<?php 
require_once ('facebook.php');
$facebookappid = $this->config->item('facebook_app_id');
$facebookseckey = $this->config->item('facebook_secret_key');

if (!empty($list_news)){         // get news listing
foreach($list_news as $row){ 
	$comment_count = $this->News_model->get_comment_count($row['article_number']);   
	$newstitle = $row['article_heading'];
	$titletoshow = strtolower($this->News_model->clean_url($newstitle));	
	$getnewsimage = $this->News_model->getfirstimage($row['news_id']);
	$facebook = new Facebook(array("appId"=>$facebookappid,"secret"=>$facebookseckey,'cookie' => true));
	$testurl = base_url()."news/news_article/".$row['article_number']."/".$titletoshow;
	$fqlquery = "SELECT share_count, like_count, click_count FROM link_stat WHERE url='" . $testurl . "'";
	$param = array(
	'method' => 'fql.query',
	'query' => $fqlquery,
	'callback' => ''
	);
	$likes = $facebook->api($param);
	$likecount = $likes[0]['like_count'];
	$this->News_model->insert_like_count($row['news_id'],$likecount);
	?>
<!--<div style="float:left; width:50px ">-->
<?php
$user_info = $this->News_model->get_user_avator($row['id_user_tiab']);	
if(!empty($newstitle)){

//Get user avator
//Please remove static if the image is not showing.
?><li style="padding-left:0">
<?php 
	if((!empty($getnewsimage[0]['news_image'])) && (file_exists("./uploads/news_photo/crop/".$getnewsimage[0]['news_image']))){?>
    <a href="<?php echo site_url('/news/news_article/'.$row['article_number'].'/'.$titletoshow.'/') ?>"><img src="<?php echo base_url();?>uploads/news_photo/crop/<?php echo $getnewsimage[0]['news_image'] ?> " width="52" height="52" alt="image"></a>
<?php } else {?> 
    <a href="<?php echo site_url('/news/news_article/'.$row['article_number'].'/'.$titletoshow.'/') ?>"><img height="52" width="52" src="<?php echo base_url(); ?>xhtml/img/badut.gif"/></a>
<?php }?>
<!--</div>
<div style="float:left">-->
<a class="news_head" href="<?php echo site_url('/news/news_article/'.$row['article_number'].'/'.$titletoshow.'/') ?>">
<?php echo $row['article_heading'] ?> </a> <br />
<!--<a href="<?php echo site_url('/news/news_article/'.$row['article_number'].'/'.$titletoshow.'/') ?>">-->
<span class="purple"><a href="<?php echo site_url('/news/news_article/'.$row['article_number'].'/'.$titletoshow.'/') ?>">...Read More </a> 
| Posted on <?php echo $row['created_date'] ?>  | <strong><?php echo $comment_count ?> Comments </strong>
| <strong><?php echo $likecount ?> Likes</strong> | Read <?php echo $row['view_count'] ?> times </span>
</li>
<!--</div>
<div class="clear"></div>-->
<?php
}
}
} else { ?>
<!--<div>No News</div>-->
<li>No news to display yet</li>
<?php
}
?>
</ol>
<!--</div>-->
<div class="prevnext">
<?php echo $this->pagination->create_links(); ?>
</div>
<!--<div class="clear"></div>-->
<hr />
    <?php $this->load->view(TEMPLATE_NAME.'/front/footer_menu');?>
</div><!-- page -->

<?php $this->load->view(TEMPLATE_NAME.'/front/side_right');?> 
<?php $this->load->view(TEMPLATE_NAME.'/front/footer');?> 
